'use strict';
const querystring = require("querystring");

module.exports = (request, response, rfun)=>{
    let d = Buffer.allocUnsafe(0);
    request.on("data", (chunk)=>{
        d = Buffer.concat([d, chunk], d.length + chunk.length);
    });
    request.on('end', ()=>{
        if(d.length > 0){
            request.POSTBUF = d;
            if(request.headers["content-type"] && request.headers["content-type"].indexOf("application/json") != -1) request.POST = JSON.parse(d.toString());
            else request.POST = querystring.parse(d.toString());
        }
        rfun && rfun();
    });
}